<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="guestbook.Greeting" %>
<%@ page import="guestbook.PMF" %>

<html>
<head>
<title>Hi~ I'm CantaPerMe.</title>
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
</head>
<body>

<h1>CantaPerMe's Life Story</h1>
<h2>Do you know me?</h2> 

<%
	UserService userService = UserServiceFactory.getUserService();
	User user = userService.getCurrentUser();
	if (user != null) {
%>
<p>Hello, <%= user.getNickname() %>! (You can
<a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">sign out</a>.)</p>
<%
	} else {
%>
<p>Hello!
<a href="<%= userService.createLoginURL(request.getRequestURI()) %>">Sign in</a>
to include your name with greetings you post.</p>
<%
	}
%>

<div id="outer">
	<div id="content">
		<!-- Primary content: Stuff that goes in the primary content column (by default, the left column) -->
		<div id="primarycontainer">
			<div id="primarycontent">
				
				<h3>Contents List...</h3>
				<%
					PersistenceManager pm = PMF.get().getPersistenceManager();
					String query = "select from " + Greeting.class.getName()+ " order by date desc";
					List<Greeting> greetings = (List<Greeting>) pm.newQuery(query).execute();
					if (greetings.isEmpty()) {
				%>
				<p>The guestbook has no messages.</p>
				<%
					} else {
						for (Greeting g : greetings) {
							if (g.getAuthor() == null) {
				%>
				<p>An anonymous person wrote:</p>
				<%
							} else {
				%>
				<p><b><%= g.getId() %> . <%= g.getAuthor().getNickname() %></b> wrote: <%= g.getDate() %></p>
				<%
							}
				%>
				<p>
				<b>Who:</b> <%= g.getWho() %> <br/>
				<b>When:</b> <%= g.getWhen() %><br/>
				<b>Where:</b> <%= g.getWhere() %><br/>
				<b>What:</b> <%= g.getWhat() %><br/>
				<b>How:</b> <%= g.getHow() %><br/>
				<b>Why:</b> <%= g.getWhy() %><br/>
				</p>
				<blockquote><%= g.getContent() %></blockquote>
				<%
						}
					}
					pm.close();
				%>
		
				<!-- Primary content area end -->
			</div>
		</div>

		
		<!-- Secondary content: Stuff that goes in the secondary content column (by default, the narrower right column) -->
		<div id="secondarycontent">
			<h3>Write your LifeStory..</h3>
			<form action="/sign" method="post">
			    <TABLE>
				  <TR>
					<TD>Who?: </TD><TD><input type="text" name="who" cols="15" /></TD>
				  </TR>
				  <TR>
					<TD>When?: </TD><TD><input type="text" name="when" cols="15" /></TD>
				  </TR>
				  <TR>
					<TD>Where?: </TD><TD><input type="text" name="where" cols="15" /></TD>
				  </TR>
				  <TR>
					<TD>What?: </TD><TD><input type="text" name="what" cols="15" /></TD>
				  </TR>
				  <TR>
					<TD>How?: </TD><TD><input type="text" name="how" cols="15" /></TD>
				  </TR>
				  <TR>
					<TD>Why?: </TD><TD><textarea name="why" rows="2" cols="17"></textarea></TD>
				  </TR>
			  	</TABLE>
		      <div><textarea name="content" rows="3" cols="27"></textarea></div>
		      <div><input type="submit" value="Post Greeting" /></div>
		    </form>
			<!-- Secondary content area end -->
		</div>


	</div>

	
</div>

</body>
</html>
